﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Bullet : MonoBehaviour {

	public float moveSpeed = 1;

	public bool isPlayerBullet;

	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
		transform.Translate(transform.up * moveSpeed*Time.deltaTime,Space.World);
	}

	private void OnTriggerEnter2D(Collider2D collider) {
		//触发检测
		switch (collider.tag) {
			case "Tank":
				if (!isPlayerBullet) { //不是玩家的子弹,敌人的
					collider.SendMessage("Die");
					Destroy(gameObject);
				}
				break;
			case "Heart":
				collider.SendMessage("Die");
				Destroy(gameObject);
				break;
			case "Enemy":
				if (isPlayerBullet) {
					collider.SendMessage("Die");
					Destroy(gameObject);
					PlayerManager.Instance.playerSocre++;
				}
				break;
			case "Wall":
				if (isPlayerBullet)
				{
					collider.SendMessage("playAudio");
				}
				Destroy(collider.gameObject);
				Destroy(gameObject);
				break;
			case "Barrier":
				if (isPlayerBullet)
				{
					collider.SendMessage("playAudio");
				}
				Destroy(gameObject);
				break;
			case "Bullet":
				if (isPlayerBullet)
				{
					Destroy(gameObject);
					Destroy(collider.gameObject);
				}
				//Destroy(gameObject);
				break;
			default:break;
		}
	}

	
}
